
define(['app', 'filters/filters'], function(app) {
	app.register.controller('myTask', function($scope, $http, $state, $sce, $stateParams, $rootScope,$cookieStore) {
        $scope.loading_show = true;
        $scope.number = 1;
		$scope.load = {
            _getchapterList:function(){
                $scope.blan = false;
                $scope.allcourse = [];
                $scope.otherMajorList = [];
                $scope.isfirst = [];
                $scope.specialty_id = [];

                $scope.sec = [];

                $scope.tipModal = {
                    isShow: false,
                    title: '温馨提示',
                    data: {},
                    confirm: function() {
                        this.hide()
                    },
                    cancel: function() {
                        this.hide()
                    },
                    hide: function() {
                        this.isShow = false;
                    },
                    show: function() {
                        this.isShow = true;
                    }
                }
                if($rootScope.num==0){
                    $scope.tipModal.show();
                    $rootScope.num=1;
                }
                $http({
                    url: app._baseUrl + '/My/MyTask/specialtyList',
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                }).success(function(res) {
                    if(res.success){
                        $scope.loading_show = false;
                        $scope.Majorinfo = res.data;
                        if($scope.Majorinfo==null||$scope.Majorinfo==''){
                            $scope.blan=true;
                        }else{
                            var arr = [];
                            angular.forEach($scope.Majorinfo,function (item) {
                                angular.forEach(item,function (item1) {
                                    arr.push(item[0].specialty_id)
                                })
                            });
                            //新建数组去重
                            function unique3(array){
                                var n = [array[0]]; //结果数组
                                for(var i = 1; i < array.length; i++) {
                                    if (array.indexOf(array[i]) == i) n.push(array[i]);
                                }
                                return n;
                            }
                            arr1 = unique3(arr);
                            $scope.blan = false;

                            for (var i =0;i<arr1.length;i++){
                                $rootScope.specialty_Id = arr1[i];
                                $scope.curriculumList(i);
                                $scope.sec.push($rootScope.specialty_Id)
                            }
                        }
                    }else{
                        $scope.loading_show = false;
                        $scope.blan = true;
                    }
                });

			},
            init: function() {
                this._getchapterList && this._getchapterList();
            }
		};
        if($cookieStore.get('refurbish') == 1){
            $scope.load.init && $scope.load.init();
        }
		$scope.gostudy = function() {
                $cookieStore.put('refurbish',1)
				var url = $state.href('app.compProfession');
				window.location.href = url;				
			}
		// $rootScope.goComp = function() {
		// 		var url = $state.href('app.compProfession');
         //        $cookieStore.put('refurbish',1)
		// 		window.location.href = url;
		// 	}


		  $scope.curriculumList=function(index,specialty_id){
            if(specialty_id){
            	$scope.sec[index]= specialty_id;
            }else{
			}
			 $scope.temp = specialty_id;
        	 $http({
                    url: app._baseUrl + '/My/MyTask/curriculumList',
                    method: 'POST',
                    data:{
                    	specialty_id:specialty_id||$rootScope.specialty_Id},
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(function(res){
                    $scope.allcourse[index]= res.data;
                });
        };
		  //随堂任务
		  $scope.task = function(){
              $cookieStore.put('refurbish',1);
              $scope.number = 1;
              $scope.load.init && $scope.load.init();
		  }
        //随堂进阶
        $scope.case = function(){
            $cookieStore.put('refurbish',2);
            $scope.number = 2;
            $scope.load.init && $scope.load.init();
        }
        if($cookieStore.get('refurbish') == 2){
            $scope.case();
        }
		 //  //案例分析
        // $scope.case = function(){
        //     $scope.number = 2;
        // }
        // //突破考试
        // $scope.exm = function(){
        //     $scope.number = 3;
        // }
		$scope.goTaskCourse = function(item,index) {
			var url = $state.href('app.taskCourse', {
				curriculum_id: item.curriculum_id,curriculum_name: item.curriculum_name,index:index
			});
			window.location.href = url
		}
	})
});